class ListNode {
	constructor(val, next) {
		this.val = val === undefined ? 0 : val
		this.next = next === undefined ? null : next
	}
}
/**
 * 1669. 合并两个链表
 * @param {ListNode} list1
 * @param {number} a
 * @param {number} b
 * @param {ListNode} list2
 * @return {ListNode}
 */
var mergeInBetween = function (list1, a, b, list2) {
	let prevA = list1
	for (let i = 0; i < a - 1; i++) {
		prevA = prevA.next
	}
	let prevB = prevA
	for (let i = 0; i < b - a + 2; i++) {
		prevB = prevB.next
	}
	prevA.next = list2
	while (list2.next) {
		list2 = list2.next
	}
	list2.next = prevB
	return list1
}
